package com.maes.hughes.example.thread.base;

/**
 * Created by Hughes on 2017/5/9.
 */
public class BasicThread extends Thread{

    private int count = 0;

    public static void main(String[] args){
//        m1();


        BasicThread basicThread1 = new BasicThread();
        basicThread1.getNext();
        new Thread(new Runnable() {
            public void run() {
                BasicThread basicThread2 = new BasicThread();
                basicThread2.getNext();
                System.out.println("2:"+basicThread2.count);

            }
        }).start();

        System.out.println("1:"+basicThread1.count);
    }

    public int getNext(){
        return ++count;
    }

    private static void m1() {
        BasicThread basicThread = new BasicThread();
        Thread one = new Thread(basicThread,"one");
        Thread two = new Thread(basicThread,"two");
        Thread three = new Thread(basicThread,"three");
        one.start();
        two.start();
        three.start();
    }


    @Override
   synchronized public void run() {
        super.run();
        count++;
        System.out.print("thread="+Thread.currentThread().getName()+",count="+count+"\n");
    }
}
